//
//  BanBu_PersonAlbumCell.m
// Halfarea
//
//  Created by linlin Yin on 14-5-30.
//
//

#import "BanBu_PersonAlbumCell.h"

@implementation BanBu_PersonAlbumCell


- (void)dealloc
{
    [_albumArr release];
    _albumArr = nil;
    self.singleTapOnAlbumCallBack = nil;
    [super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _albumArr = [[NSMutableArray alloc]initWithCapacity:3];
        for (int i = 0; i < 3; i ++)
        {
            CGFloat x = i % 3 * 107;
            CGFloat y = i / 3 * 125 + 5;
            
            UIImageView * totalImgV = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, 107, 125)];
            totalImgV.userInteractionEnabled = YES;
            UIImageView * kuangImgV = [[UIImageView alloc]initWithFrame:CGRectMake(10.5, 0, 85, 84)];
            kuangImgV.tag = 1001;
            [totalImgV addSubview:kuangImgV];
            
            UIImageView * photoImgV = [[UIImageView alloc]initWithFrame:CGRectMake(17, 5, 68, 68)];
            photoImgV.tag = 1002;
            photoImgV.layer.cornerRadius = 8.0;
            photoImgV.layer.masksToBounds = YES;
            [totalImgV addSubview:photoImgV];
            UIImageView * numBack = [[UIImageView alloc]initWithFrame:CGRectMake(10.5, 0, 24, 15)];
            numBack.image = [UIImage imageNamed:@"album_numBack2.png"];
            [totalImgV addSubview:numBack];
            [numBack release];
            UILabel * numLabel = [[UILabel alloc]initWithFrame:CGRectMake(10.5, 0.5, 24, 11)];
            numLabel.tag = 1004;
            numLabel.backgroundColor = [UIColor clearColor];
            numLabel.font = [UIFont systemFontOfSize:10.5];
            numLabel.textAlignment = kTextAlignmentCenter;
            numLabel.textColor = [UIColor whiteColor];
            [totalImgV addSubview:numLabel];
            [numLabel release];
            UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTapPressed:)];
            totalImgV.userInteractionEnabled = YES;
            [totalImgV addGestureRecognizer:singleTap];
            totalImgV.tag = 100 + i;
            [photoImgV release];
            
            UILabel * infoLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 85, 105, 25)];
            infoLabel.font = [UIFont systemFontOfSize:12.0];
            infoLabel.backgroundColor = [UIColor clearColor];
            infoLabel.tag = 1003;
            infoLabel.textAlignment = NSTextAlignmentCenter;
            [totalImgV addSubview:infoLabel];
            [infoLabel release];
            [self.contentView addSubview:totalImgV];
            [totalImgV release];
            
        }
    }
    return self;
}


#pragma mark - 点击单个相册
- (void)singleTapPressed:(UITapGestureRecognizer *)singleTap
{
    if (_singleTapOnAlbumCallBack)
    {
        _singleTapOnAlbumCallBack(singleTap.view.tag - 100, _albumArr);
    }
}

- (void)updatePersonAlbumCellData:(NSArray *)array
{
    [_albumArr removeAllObjects];
    [_albumArr addObjectsFromArray:array];
    for (int i = 0; i < 3; i ++)
    {
        UIImageView * totalImgV = (UIImageView *)[self.contentView viewWithTag:100 + i];
        [totalImgV setHidden:YES];
    }
    NSInteger tag = 0;
    for (BanBu_AlbumModel * album_model in array)
    {
        if ([album_model.album_title isEqualToString:@"fffff"])
        {
            NSLog(@"cgdshdf");
        }
        UIImageView * totalImgV = (UIImageView *)[self.contentView viewWithTag:100 + tag];
        [totalImgV setHidden:NO];
        //相册底
        UIImageView * kuangImgV = (UIImageView *)[totalImgV viewWithTag:1001];
        //封面图片
        UIImageView * photoImgV = (UIImageView *)[totalImgV viewWithTag:1002];
        //相册名称
        UILabel * infoLabel = (UILabel *)[totalImgV viewWithTag:1003];
        //相册内照片数量
        UILabel * numLabel = (UILabel *)[totalImgV viewWithTag:1004];
        photoImgV.image = nil;
        if ([album_model.album_id isEqualToString:Album_privacy])
        {
            kuangImgV.image = [UIImage imageNamed:@"album_private.png"];
        }
        else
        {
            if (album_model.personalbum_type == CREATE_QUESSTION)
            {
                kuangImgV.image = [UIImage imageNamed:@"album_encryption.png"];
                
            }
            else if (album_model.personalbum_type == CREATE_PRIVATE)
            {
                kuangImgV.image = [UIImage imageNamed:@"album_private.png"];
            }
            else
            {
                kuangImgV.image = [UIImage imageNamed:@"album_public.png"];
                if (album_model.image_url && ([album_model.image_url isKindOfClass:[NSString class]]))
                {
                    NSLog(@"%@ %@",album_model.album_id,album_model.image_url);
                    [photoImgV setImageWithURL:[NSURL URLWithString:album_model.image_url]
                                        andCut:YES];
                }
            }
        }
        numLabel.text = [NSString stringWithFormat:@"%d",album_model.numCount];
        infoLabel.text = album_model.album_title;
        tag ++ ;
    }

}
- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
